{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.common import PayReceive, Currency\n",
    "from gs_quant.instrument import IRSwap\n",
    "from gs_quant.session import Environment, GsSession\n",
    "from gs_quant.risk import DollarPrice, IRDelta\n",
    "from gs_quant.markets import PricingContext\n",
    "from datetime import date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "swap = IRSwap(PayReceive.Pay, '12y', notional_currency=Currency.GBP)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "Metrics - aggregation level",
     "Metrics"
    ]
   },
   "outputs": [],
   "source": [
    "# if you set an aggregation level for a risk ladder like IRDelta it will change to be filtered at the market coordinate level\n",
    "# levels are:  type, asset, class, point and quoting style.  type is at the metric level.\n",
    "# in this case when setting the aggregation level to Type the model will do a simple parallel shift rather than calculating\n",
    "# the perturbated risk and aggregating.\n",
    "\n",
    "with PricingContext(pricing_date=date(2019, 1, 15)):\n",
    "    res_f = swap.calc((DollarPrice, IRDelta, IRDelta(aggregation_level='Type')))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(res_f.result())  # retrieve all measures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "Results - Retrieve Specific Measure"
    ]
   },
   "outputs": [],
   "source": [
    "print(res_f[DollarPrice])  # retrieve specific measure"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "metadata": {
     "collapsed": false
    },
    "source": []
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
